package Servlet;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;


public class GestoreContesto {
	private static Context getInitialContext() throws javax.naming.NamingException{
		Properties p= new Properties();
		p.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
		p.put("java.naming.provider.url", "jnp://localhost:1099");
		p.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");

		return new javax.naming.InitialContext(p);
	}
	
	public <T> T getGestore(Class<T> interfaccia, String nomeClasse) throws NamingException{
		Context jndiContext = getInitialContext();
		Object ref = jndiContext.lookup(nomeClasse);
		@SuppressWarnings("unchecked")
		T gestore = (T)PortableRemoteObject.narrow(ref, interfaccia);
		return gestore;
	}
}
